package com.chunuo.vod.controller;

import com.aliyuncs.DefaultAcsClient;
import com.chunuo.commonutils.R;
import com.chunuo.vod.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.POST;
import java.util.List;

/**
 * 类的作用
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-07-15 22:04
 */
//@CrossOrigin
@RequestMapping("/eduvideo/video")
@RestController
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService;

    @PostMapping("/uploadVideo")
    public R uploadVideoAliyun(MultipartFile file){
        String videoId = eduVideoService.uploadVideo(file);
        return R.ok().data("videoId",videoId);
    }

    @DeleteMapping("/removeAlyVideo/{id}")
    public R removeAlyVideo(@PathVariable("id")String id){
        if(!StringUtils.isEmpty(id)){
            eduVideoService.removeAlyVideo(id);
        }
        return R.ok();
    }

    @DeleteMapping("/removeCourseVideo/{ids}")
    public R removeCourseVideo(@PathVariable("ids")String ids){
        if(!StringUtils.isEmpty(ids)){
            eduVideoService.removeAlyVideo(ids);
        }
        return R.ok();
    }

    //根据视频id获取视频凭证
    @GetMapping("getPlayAuth/{id}")
    public R getPlayAuth(@PathVariable String id) {
        String playAuth = eduVideoService.getPlayAuth(id);
        return R.ok().data("playAuth",playAuth);
    }
}
